﻿@model user.admin.cyt369.com.services.Models.Terms
@{
    Layout = null;
    var plugName = @user.admin.cyt369.com.Areas.UserAdmin.Models.PlugName.Name;
    var tableName = this.Context.Request.Query["tbl"];
    var editDlgName = this.Context.Request.Query["dlg"];
    var saveEditFunName = PageViewModel.PageFunctionName(this, "save_terms");
    var closeEditFunName = PageViewModel.PageFunctionName(this, "close_terms");
}

<div class="easyui-layout" fit="true">
    <div data-options="region:'north'" style="height:50px;padding:10px;overflow:hidden">
        <a href="javascript:@saveEditFunName ()" class="easyui-linkbutton" data-options="iconCls:'icon-save'"> 保 存 </a>
        <a href="javascript:@closeEditFunName ()" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'"> 关 闭 </a>
        <script type="text/javascript">
            function @saveEditFunName () {
                var form = $("#@editDlgName").find("form");
                if (form.form('enableValidation').form('validate')) {
                    var item = form.form_to_json(function (form, item) {
                        item.Content = UE.getEditor('terms-editor-text-area').getContent();
                        item.Status = (form.find("#Status").switchbutton("options").checked ? 1 : 0);
                        item.IsPublished = form.find("#IsPublished").switchbutton("options").checked;
                    });
                    $.ajax({
                        url: "~/@plugName/Terms/SaveTerms",
                        type: "POST",
                        data: item,
                        success: function (e) {
                            if (e.Result) {
                                $.messager.alert('保存成功', '保存成功!', 'info', function () {
                                    $('#@editDlgName').dialog('close');
                                    $('#@tableName').datagrid('reload');
                                });
                            } else {
                                $.messager.alert('保存失败', '保存失败: ' + e.Msg, 'error');
                            }
                        },
                        error: function (e) {
                            ShowAjaxError(e);
                        }
                    });
                }
            }

            function @closeEditFunName () {
                $("#@editDlgName").dialog("close");
            }
        </script>
    </div>
    <div data-options="region:'west',split:true" style="width: 200px;overflow: hidden">
        <span class="fileinput-button upload-btn">
            <span>+上传图片</span>
            <input type="file" multiple="multiple" id="_upload_img_btn" name="_upload_img_btn[]" />
        </span>
        <form id="image-form">
            <ul id="image-panel-list" class="image-list">
            </ul>
        </form>
    </div>
    <div data-options="region:'center'">
        <form id="terms-edit-form">
            <table class="form_table" style="width:100%">
                <tr>
                    <td align="right">协议名称：</td>
                    <td>
                        <input name="Id" id="Id" style="display:none" value="@(Model==null?0:Model.Id)" />
                        <input name="Name" class="easyui-textbox" style="width: 800px;" data-options="required:true" />
                    </td>
                </tr>
                <tr>
                    <td width="140" align="right">编号：</td>
                    <td>
                        <input name="No" class="easyui-textbox" style="width: 250px;" data-options="required:true" />
                        <span>版本：</span>
                        <input name="Version" class="easyui-textbox" style="width: 250px;" />
                    </td>
                </tr>
                <tr>
                    <td align="right">类型：</td>
                    <td>
                        <input class="easyui-combobox" name="TermsTypeID" id="TermsTypeID" style="width:350px"
                               data-options="required:true,editable:false,textField:'Name',valueField:'Id',url:'~/@plugName/Terms/GetAllTermTypes'" />
                        <span align="right">状态：</span>
                        <input id="Status" name="Status" class="easyui-switchbutton" checked data-options="onText:'有效',offText:'无效'" style="width:100px;height:25px;" />
                        <span align="right">是否发布：</span>
                        <input id="IsPublished" name="IsPublished" class="easyui-switchbutton" checked data-options="onText:'是',offText:'否'" style="width:100px;height:25px;" />
                    </td>
                </tr>
                <tr>
                    <td align="right">主要内容：</td>
                    <td>
                        <div id="terms-editor-text-area" class="container" style="width:800px;min-height:300px"></div>
                    </td>
                </tr>
            </table>
            <script type="text/javascript">
                $(document).ready(function () {
                    var toolbar = [
                        ['undo', 'redo', '|',
                            'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
                            'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
                            'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
                            'directionalityltr', 'directionalityrtl', 'indent', '|',
                            'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
                            'pagebreak', 'horizontal', 'date', 'time', '|',
                            'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts', '|',
                        ]
                    ];
                    var editor = UE.getEditor('terms-editor-text-area', { zIndex: 9801, autoHeightEnabled: true, toolbars: toolbar });
                    editor.ready(function () {
                        var id = parseInt($("#@editDlgName").find("#terms-edit-form").find("#Id").val());//加载内容
                        if (id > 0) {
                            $.ajax({
                                url: "~/@plugName/Terms/GetTermsByID/" + id,
                                type: "GET",
                                contentType: 'application/json',
                                success: function (item) {
                                    if (item != null) {
                                        var form = $("#@editDlgName").find("form");
                                        form.form("load", item);
                                        if (item.IsPublished) {
                                            form.find("#IsPublished").switchbutton("check");
                                        } else {
                                            form.find("#IsPublished").switchbutton("uncheck");
                                        }
                                        if (item.Status==1) {
                                            form.find("#Status").switchbutton("check");
                                        } else {
                                            form.find("#Status").switchbutton("uncheck");
                                        }
                                        UE.getEditor('terms-editor-text-area').setContent(item.Content);
                                    }
                                },
                                error: function (e) {
                                    alert("error:" + e);
                                }
                            });
                        }
                    });
                });
            </script>
        </form>
    </div>
</div>


